package com.codeoss.module.ir.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codeoss.framework.service.impl.BaseService;
import com.codeoss.framework.util.ValueNamePair;
import com.codeoss.module.ir.dao.IrDictMapper;
import com.codeoss.module.ir.model.IrDict;
import com.codeoss.module.ir.model.IrDictLine;
import com.codeoss.module.ir.service.IIrDictLineService;
import com.codeoss.module.ir.service.IIrDictService;

@Service
public class IrDictService extends BaseService<IrDictMapper, IrDict> implements IIrDictService {
	@Autowired
	private IIrDictLineService irDictLineService;
	@Override
	public List<ValueNamePair> getPairListByCode(String code) {
		// TODO Auto-generated method stub
		List<ValueNamePair> pairList=new ArrayList<ValueNamePair>();
		
		QueryWrapper<IrDict> dictQuery=new QueryWrapper<IrDict>();
		dictQuery.eq("code", code);
		IrDict irDict=getOne(dictQuery);
		
		QueryWrapper<IrDictLine> lineQuery=new QueryWrapper<IrDictLine>();
		lineQuery.eq("ir_dict_id", irDict.getId());
		List<IrDictLine> lineList=irDictLineService.list(lineQuery);
		
		for(int i=0;i<lineList.size();i++) {
			IrDictLine line=lineList.get(i);
			ValueNamePair pair=new ValueNamePair(line.getName(),line.getCode());
			pairList.add(pair);
		}
		return pairList;
	}
	@Override
	public IrDict getIrDictByCode(String code) {
		// TODO Auto-generated method stub
		QueryWrapper<IrDict> dictQuery=new QueryWrapper<IrDict>();
		dictQuery.eq("code", code);
		IrDict irDict=getOne(dictQuery);
		return irDict;
	}
	
	
	
}